package Test;
//在测试类中，定义集合ArrayList，并声明Book泛型，将文本中每一行内容封装成Book对象并读取到集合中；
//
//   3：程序启动，要求遍历集合,计算出每本书的总价,与所有书的总价打印到控制台
//(30分)反馈该题
//Java基础教程,55.00,12
//深入浅出JavaEE,53.00,34
//MySQL使用指南,62.00,15
//IOS从入门到精通,85.00,17
//Java破天宝典,110.10,2
import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

//Java基础教程,共计xxx元
//深入浅出JavaEE,共计xxx元
//MySQL使用指南,共计xxx元
//IOS从入门到精通,共计xxx元
//Java破天宝典,共计xxx元
//图书总金额为:xxx元
public class Test_1 {
    public static void main(String[] args) throws IOException {
        ArrayList<Book>list=new ArrayList<>();
        BufferedReader br=new BufferedReader(new FileReader("D:\\IdeaProjects\\Advance" +
                "\\src\\Test\\Book.txt"));
        String len="";
        while ((len=br.readLine())!=null){
            String[] split = len.split(",");
            Book book=new Book();
            book.setName(split[0]);
            book.setPrice(split[1]);
            book.setSum(split[2]);
            list.add(book);
        }
        Map<String,String> map=new HashMap<>();
        double s=0;

        for (int i = 0; i < list.size(); i++){
            Book book = list.get(i);
            String price = book.getPrice();
            String price1 = book.getPrice();
            double v = Double.parseDouble(price1);
            String sum = book.getSum();
            int i1 = Integer.parseInt(sum);
            Double value=i1*v;
            s+=value;
            map.put(book.getName(),"共计"+value);
        }
        Set<Map.Entry<String, String>> entries = map.entrySet();
        for (Map.Entry<String, String> entry : entries) {
            String key = entry.getKey();
            String value = entry.getValue();
            System.out.println(key+" "+value);
        }
        System.out.println("共计"+s);
    }
}
